<template>
  <div class="nav-bar-wrap">
    <!-- 返回按钮 -->
    <div class="back" @touchstart="back"></div>
    <div class="status-bar w-full"></div>
    <div class="nav-bar w-full flex flex-row justify-between items-center box-border relative">
      <!-- 返回箭头 -->
      <div class="icon h-full flex items-center">
        <img src="static/icons/back.png" mode="" />
      </div>
      <!-- 标题 -->
      <div class="title text-white absolute">
        {{ title }}
      </div>
      <!-- 自定义按钮 -->
      <slot name="custom"></slot>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: ''
    },
    onBack: {
      type: [Function, undefined],
      default: undefined
    }
  },
  data() {
    return {}
  },
  methods: {
    back() {
      if (this.onBack) {
        this.onBack()
      } else {
        this.$router.go(-1)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.nav-bar-wrap {
  background: linear-gradient(270deg, #51c3ff 0%, #88e0ff 100%);
  position: relative;

  .back {
    position: absolute;
    left: 0;
    top: 0;
    width: 81px;
    height: 81px;
    z-index: 1;
  }

  .status-bar {
    height: 25px;
  }

  .nav-bar {
    height: 56px;
    padding-right: 20px;

    .icon {
      width: 65px;

      img {
        width: 11.43px;
        height: 20px;
        margin-left: 20px;
      }
    }

    .title {
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: 24px;
    }
  }
}
</style>
